package com.transcargo.geo;

import java.util.ArrayList;
import java.util.Iterator;

import com.transcargo.db.db;
import com.transcargo.db.dbException;

public class Region {
	private String name = "";
	private int Country_id = -1;
	private int Id = -1;
/*
    private City[] cities = null;
	private int num_cities = 0;
*/
	
	public Region(int id, int country_id, db Db) throws GeoObjectNotFoundException, dbException
	{
		Country_id = country_id;
		Id = id;
		ArrayList<String[]> list = Db.execute("SELECT name FROM regions WHERE reg_id=" + Integer.toString(id) + " and country_id=" + Integer.toString(country_id));
		if (list != null) {
			Iterator<String[]> iter = list.iterator();
            if (iter == null || !iter.hasNext()) throw new GeoObjectNotFoundException(new com.transcargo.geo.Object(null, this, null));
			String[] ctr = iter.next();
			name = ctr[0];
/*
            list = Db.execute("SELECT city_id FROM cities WHERE country_id=" + Integer.toString(country_id) + " and reg_id=" + Integer.toString(id));
			if (list != null) {
				iter =list.iterator();
				num_cities = list.size();
				cities = new City[num_cities];
				int i = 0;
				while (iter.hasNext()) {
					ctr = iter.next();
					int city_id = Integer.parseInt(ctr[0]);
					cities[i] = new City(city_id, country_id);
					i++;
				}
			}*/
		} else throw new GeoObjectNotFoundException(new com.transcargo.geo.Object(null, this, null));
	}
	public String getName() {
		return name;
	}
/*
    public City[] getCities() {
		return cities;
	}
	public int getNumCities() {
		return num_cities;
	}
*/
    public int getId() {
        return Id;
    }
    public int getCountryId() {
        return Country_id;
    }
}